# Contributor: Simon Frankenberger <simon-alpine@fraho.eu>
# Maintainer: Simon Frankenberger <simon-alpine@fraho.eu>
pkgname=java-jtreg
pkgver=5.1_p01
_pkgver=${pkgver/_p/-b}
pkgrel=0
pkgdesc="jtreg is the test harness used by the JDK test framework"
url="https://hg.openjdk.java.net/code-tools/jtreg"
arch="noarch !mips !mips64" # java
license="GPL-2.0"
depends="java-jtharness java-asmtools"
makedepends="openjdk8 zip"
options="!check" # the tests require an X11 or VNC display
#subpackages="$pkgname-doc:_doc $pkgname-examples:_examples"
source="jtreg-$_pkgver.tar.bz2::https://hg.openjdk.java.net/code-tools/jtreg/archive/jtreg$_pkgver.tar.bz2
https://archive.apache.org/dist/ant/binaries/apache-ant-1.9.13-bin.tar.bz2
https://repo1.maven.org/maven2/junit/junit/4.10/junit-4.10.jar
https://repo1.maven.org/maven2/org/testng/testng/6.9.5/testng-6.9.5.jar
https://repo1.maven.org/maven2/com/beust/jcommander/1.72/jcommander-1.72.jar

jtreg-symlink-patch.txt
jtdiff-symlink-patch.txt
"
builddir="$srcdir/jtreg-jtreg$_pkgver"

build() {
	mkdir -p "$builddir"/build
	make JTHARNESS_HOME=/usr/share/java/jtharness \
		ANTHOME="$srcdir"/apache-ant-1.9.13 \
		ASMTOOLS_HOME=/usr/share/java/asmtools \
		JDKHOME=/usr/lib/jvm/default-jvm \
		JUNIT_HOME="$srcdir" \
		TESTNG_HOME="$srcdir" \
		JCOMMANDER_JAR="$srcdir"/jcommander-1.72.jar \
		TOUCH=/bin/touch \
		-C make
}

package() {
	_destdir="$pkgdir/usr/share/java/jtreg"
	mkdir -p "$_destdir"
	cp -r \
		$builddir/build/images/jtreg/bin\
		$builddir/build/images/jtreg/legal \
		$builddir/build/images/jtreg/lib \
		$builddir/build/images/jtreg/COPYRIGHT \
		$builddir/build/images/jtreg/LICENSE \
		$builddir/build/images/jtreg/README \
		$builddir/build/images/jtreg/release \
		"$_destdir"

	# link to jtharness and asmtools from depends
	rm "$_destdir"/lib/asmtools.jar
	rm "$_destdir"/lib/javatest.jar
	ln -s /usr/share/java/asmtools/lib/asmtools.jar  "$_destdir"/lib/asmtools.jar
	ln -s /usr/share/java/jtharness/lib/javatest.jar "$_destdir"/lib/javatest.jar

	# patch the jtreg executable script to handle symlink from /usr/bin
	cd "$pkgdir"
	patch -p1 -i "$srcdir"/jtreg-symlink-patch.txt
	patch -p1 -i "$srcdir"/jtdiff-symlink-patch.txt

	mkdir -p "$pkgdir/usr/bin"
	ln -s /usr/share/java/jtreg/bin/jtdiff "$pkgdir"/usr/bin/jtdiff
	ln -s /usr/share/java/jtreg/bin/jtreg  "$pkgdir"/usr/bin/jtreg
}

_doc() {
	_destdir="$subpkgdir/usr/share/java/jtreg"
	mkdir -p "$_destdir"
	cp -r \
		$builddir/target/binaries/doc \
		"$_destdir"
}

sha512sums="64277f72847b6c182cd00fee39c817a1c510d7e6eef0dd01f3642d4ca661cd5215330ef4627e3557d4ba9eb212bdca3ef6539f1b5c0f72ba617c5a18063ef990  jtreg-5.1-b01.tar.bz2
e9b602aacbac7bf721a830f56ea06cde60a7a674a6d67f05ce82848ac01b2ee84f7003190286fea1030abb523398fa1a280d265377f41f57e7cf7e6d1fe37465  apache-ant-1.9.13-bin.tar.bz2
2c8b595c24a5ad2499a5bd5bb01204453cd09f51308fea5834922e042b8f39bd8ef0099848eb3a8576ddc4ce4ec907181ba0c20f1222a25b3064d1c3c5499cbd  junit-4.10.jar
15a6d6a3c29e6212d18c299e905620ff743825029129ce44d70cadbff589873bfc983f79b9a50052b85b03c8dac25ef5cf9de1628e10db980a4ac94c66173475  testng-6.9.5.jar
2da86589ff7ecbb53cfce845887155bca7400ecf2fdfdef7113ea03926a195a1cbcf0c071271df6bedc5cdfa185c6576f67810f6957cd9b60ab3600a4545420e  jcommander-1.72.jar
136e6e58b85d05f3e97467344c95303cbd310ada7c6533a129a6e62786d5e9498a1842b75de9838b432e68d0d863058ac5aeeea2a78e98a2170b4a0c1c113083  jtreg-symlink-patch.txt
67f63317a2aaedd17e822389065ff5d86d574f4cb2e2af375856a9c7356dd048c396517372788b889db376fe4aa73c66d530938b8975d11d7714ac84e3dcd00d  jtdiff-symlink-patch.txt"
